package com.poly.police.monitor.common.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ConvertUtils {
    private static final ObjectMapper MAPPER = new ObjectMapper();

    public ConvertUtils() {
    }

    public static <T> T convert(Object obj, Class<T> clazz) {
        if (obj != null && clazz != null) {
            try {
                String json = MAPPER.writeValueAsString(obj);
                return MAPPER.readValue(json, clazz);
            } catch (JsonProcessingException var3) {
                var3.printStackTrace();
                throw new RuntimeException("object convert exception");
            }
        } else {
            return null;
        }
    }

    public static <T> List<T> convert(List<?> objList, Class<T> clazz) {
        List<T> list = new ArrayList();
        Iterator var3 = objList.iterator();

        while(var3.hasNext()) {
            Object obj = var3.next();
            list.add(convert(obj, clazz));
        }

        return list;
    }

    static {
        MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        MAPPER.registerModule(new JavaTimeModule());
    }
}